package com.sunfield.windpower.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunfield.baseframe.base.MyRecyclerAdapter;
import com.sunfield.myglide.MyGlide;
import com.sunfield.windpower.R;
import com.sunfield.windpower.activity.DoorNewsDetailActivity_;
import com.sunfield.windpower.bean.NewsInfo;
import com.sunfield.windpower.util.Tools;

import org.androidannotations.annotations.EBean;

/**
 * Created by wxl on 2017/2/7.
 */
@EBean
public class NewsAdapter extends MyRecyclerAdapter<NewsInfo, NewsAdapter.ViewHolder> {
    public NewsAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_news, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final NewsInfo data = getItem(position);
        holder.tv_time.setText(data.getDate());
        holder.tv_title.setText(data.getTitle());
        holder.tv_content.setText(data.getContent());
        holder.tv_count.setText(Tools.parseInt(data.getNum()) + "人看过");
        MyGlide.with(context).load(data.getImage()).into(holder.iv_pic);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DoorNewsDetailActivity_.intent(context).newsId(data.getId()).start();
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public TextView tv_time;
        public TextView tv_title;
        public ImageView iv_pic;
        public TextView tv_content;
        public TextView tv_count;

        public ViewHolder(View rootView) {
            super(rootView);
            this.rootView = rootView;
            this.tv_time = (TextView) rootView.findViewById(R.id.tv_time);
            this.tv_title = (TextView) rootView.findViewById(R.id.tv_title);
            this.iv_pic = (ImageView) rootView.findViewById(R.id.iv_pic);
            this.tv_content = (TextView) rootView.findViewById(R.id.tv_content);
            this.tv_count = (TextView) rootView.findViewById(R.id.tv_count);
        }
    }
}
